/**
 * Created by yuris on 28.01.15.
 */
package InterfaceObjects {
import feathers.controls.Label;
import feathers.display.Scale3Image;
import feathers.text.BitmapFontTextFormat;

import starling.display.Sprite;
import starling.events.Event;

public class WindowTitle extends Sprite {

    private var _bgSkin:Scale3Image;
    private var _titleLabel:Label;

    public function WindowTitle(title:String) {
        super();
        this._bgSkin = new Scale3Image(GraphicFactory.getScale3Textures("Interface/Skins/window_caption"));
        this._bgSkin.alignPivot("left","top");
        this._bgSkin.useSeparateBatch = false;
        addChild(this._bgSkin);
        this._titleLabel = new Label();

        this._titleLabel.textRendererProperties.useSeparateBatch = false; //use separate if text color will change
        this._titleLabel.textRendererProperties.textFormat = new BitmapFontTextFormat("ComicDB",25,16777215,"center")//, 0x333333);//color change causes extra Draw Call
        this._titleLabel.text = title;
        this._titleLabel.maxWidth = 0.8 * this._bgSkin.width;
        this._titleLabel.validate();

        this._titleLabel.y = -3;
        this._titleLabel.x = 18;
        addChild(this._titleLabel);

        this.touchable = false;

        this.width = (title.length * 19)+10;
    }


    override public function set width(value:Number):void {
        this._bgSkin.width = value;
        this._titleLabel.maxWidth = this._bgSkin.width * 0.8;
        this._titleLabel.x = this._bgSkin.width * 0.15

    }
}
}
